export default {
  namespaced: true,
  state: {
    //是否显示提示框
    isShowToast: false,
    //提示内容
    toastMsg: "",
    //提示类型
    toastType: "success", //success danger warning
  },
  mutations: {
    //修改是否显示提示框
    changeIsShowToast(state, payload) {
      state.isShowToast = payload.isShow;
      if (payload.isShow) {
        state.toastMsg = payload.title;
        state.toastType = payload.type;
      }
    },
  },

  actions: {
    asyncIsShowToast({ commit }, payload) {
      //context.commit

      /* payload = {
        isShow: true,
        title: "请输入正确的手机号码！",
        type: "danger",
      }; */

      console.log("asyncIsShowToast*****");
      // console.log(state.toastMsg);
      //第一步，显示提示框
      commit("changeIsShowToast", payload);
      //第二步：异步操作隐藏提示框
      setTimeout(() => {
        commit("changeIsShowToast", {
          isShow: false,
        });
      }, 1000);
    },
  },
};
